export default {
	data() {
		return {
			circleLst:[],
		}
	},
	onShow(){
		this.getCircleList();
		uni.removeStorageSync('group-share-circleinfo');
	},
	methods: {
		getCircleList()
		{
			var that = this;
			if(that.$api.checkLogin() == true)
			{
				that.$http.post('circle/getUserCircleList').then(res=>{
					that.circleLst = res.data.list;
				})
			}else{
				that.circleLst = [];
			}
		},
		opeFunc(type,index){
			var that = this;
			var info = that.circleLst[index];
			switch(type)
			{
				case 'fqtj':
					that.$api.navigateTo('/pages/form/statistics/add?circle_id='+info.circle_id);
					break;
				case 'fqdk':
					that.$api.navigateTo('/pages/form/daka/add?circle_id='+info.circle_id);
					break;
				case 'edit':
					that.$api.navigateTo('/pages/group/group-edit?circle_id='+info.circle_id);
					break;
				case 'share':
					uni.setStorageSync('group-share-circleinfo',info);
					that.$api.navigateTo('/pages/group/group-share');
					break;
				case 'del':
					that.delCircle(info.circle_id);
					break;
				case 'loginout':
					that.loginOutCircle(info.circle_id);
					break;
				case 'join_user':
					if(info.join_count < 1)
					{
						that.$api.showModal('当前未有成员加入','是否立即邀请',function(res){
							console.log(res)
							if(res == 'yes')
							{
								that.opeFunc('share',index);
							}
						})
					}else{
						that.$api.navigateTo('/pages/group/group-user?circle_id='+info.circle_id);
						return ;
					}
					break;
				case 'edit-join':
					that.$api.navigateTo('/pages/group/group-join-edit?circle_id='+info.circle_id);
					return ;
			}
		},
		loginOutCircle(circle_id){
			var that = this;
			that.$api.showModal('确认退出该圈子吗','',function(res){
				if(res == 'yes')
				{
					that.$http.post('circle/loginOutCircle',{
						circle_id
					}).then(res=>{
						that.$api.msg(res.msg);
						if(res.code == 1)
						{
							that.getCircleList(); //重新获取一遍信息
						}
					});
				}
			})
		},
		delCircle(circle_id){
			var that = this;
			that.$api.showModal('确认删除','删除后不可恢复',function(res){
				if(res == 'yes')
				{
					that.$http.post('circle/delUserCircleInfo',{
						circle_id
					}).then(res=>{
						that.$api.msg(res.msg);
						if(res.code == 1)
						{
							that.getCircleList(); //重新获取一遍信息
						}
					});
				}
			})
		},
		openUrl(type){
			var that = this;
			switch(type)
			{
				case 'add':
					that.$api.navigateTo('/pages/group/group-add');
					break;
				case 'join':
					that.$api.navigateTo('/pages/group/group-join');
					break;
					
			}
		}
	}
}